<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="renderer" content="webkit">
  <title></title>
  <link rel="stylesheet" href="__CSS__/pintuer.css?v={$src_version}">
  <link rel="stylesheet" href="__CSS__/admin.css?v={$src_version}">
  <link rel="stylesheet" href="__CSS__/responsive.css?v={$src_version}">
  <script src="__JS__/jquery-3.2.1.min.js?v={$src_version}"></script>
  <script src="__JS__/pintuer.js?v={$src_version}"></script>
  <script src="https://cdn.bootcss.com/jquery.nicescroll/3.7.6/jquery.nicescroll.js"></script>
  <script src="__PUBLIC__/layer.js?v={$src_version}"></script>
  <script src="__JS__/ming.js?v={$src_version}"></script>
  <script src="__JS__/ifram_scroll.js?v={$src_version}"></script>
  <script src="__JS__/responsive.js?v={$src_version}"></script>
  <body>
    <div class="panel admin-panel">
      <div class="padding">
        <form method="post" action="{:U('Goods/index')}?act=search" class="search-form" id="frm1">
          <ul class="search" >
            <li>
              <input type="text" value="{$con.keywords}" placeholder="请输入商品名称" name="keywords" class="input search-input" />
            </li>
            <li>
              <a href="javascript:void(0)" class="button border-main icon-search" id="dosearch" style="padding: 10px 15px;"> 搜索</a>

            </li>
          </ul>

        </form>

      </div>
      <a type="button" class="button border-yellow" onclick="window.location.href='{:U('Goods/add')}'" style="display:block;width:80px;padding:3px 5px; ">
        <span class="icon-plus-square-o"></span>添加商品</a>

      <table class="table table-hover text-center">
        <tr>
          <th></th>
          <th style="text-align:left;">商品名称</th>
          <th>商品详情</th>
          <th>商品图片</th>
          <th>所需积分</th>
          <th>排序</th>
          <th>操作</th>
        </tr>
        <volist name="goods" id="v">
          <tr>
            <td style="text-align:left; padding-left:20px;">
              <input type="checkbox" name="id[]" value="{$v.gid}" />
            </td>
            <td style="text-align:left;">{$v.gname}</td>
            <td>{$v.gdesc}</td>
            <td style=" height:50px;">
              <a href="/{$v.pics}" target="_blank">
                <img src="/{$v.pics}" style="display:block; margin:0 auto; height:100%; width:auto; overflow:hidden;" />
              </a>
            </td>
            <td>{$v.gpoint}</td>
            <td>{$v.sort}</td>
            <td>
              <div class="button-group">
                <a class="button border-main" href="{:U('Goods/add')}?id={$v.gid}">
                  <span class="icon-edit"></span> 修改</a>
                <a class="button border-red" href="javascript:void(0)" onclick="return del({$v.gid})">
                  <span class="icon-trash-o"></span> 删除</a>
              </div>
            </td>
          </tr>
        </volist>

        <?php if(intval(count($goods))>0){ ?>


        <tr class="no-hover">
          <td style="text-align:left; padding:19px 0;padding-left:20px;">
            <input type="checkbox" id="checkall" /> 全选 </td>
          <td colspan="80" style="text-align:left;padding-left:20px;">
            <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="DelSelect()">
            删除</a>

          </td>
        </tr>

        <tr class="no-hover" style="border-bottom:none">
          <td style="border-bottom:none" colspan="80">
            <div class="pagelist">
              <?php echo $page; ?>
            </div>
          </td>
        </tr>

        <?php }else{ ?>

        <tr class="no-hover">
          <td style="border-bottom:none" colspan="80">
            <div class="pagelist">
              <?php  echo '暂无记录'; ?>
            </div>
          </td>
        </tr>

        <?php } ?>
      </table>
    </div>

    <script type="text/javascript">

      $(function () {
        //搜索
        $('#dosearch').click(function () { $('#frm1').submit(); });

      });


      //单个删除
      function del(id) {
        layer.confirm('您确定要删除吗?', {
          btn: ['确定', '取消'] //按钮
        }, function () {

          //执行删除操作
          $.ajax({
            type: 'post',
            url: "{:U('Goods/del')}",
            data: { id: id },
            dataType: 'json',
            success: function (res) {
              layer.msg(res.msg, { icon: res.code });
              res.code == '1' ? setTimeout("goURL('" + res.url + "')", 500) : '';
            }
          });



        });

      }

      //全选
      $("#checkall").click(function () {

        if (this.checked) {
          $("input[name='id[]']").each(function () {
            this.checked = true;
          });
        }
        else {
          $("input[name='id[]']").each(function () {
            this.checked = false;
          });

        }


      });
      //设置全选复选框
      $("input[name='id[]']").click(function () {
        allchk();
      });
      function allchk() {

        var chknum = $("input[name='id[]']").length;//选项总个数
        var chk = 0;
        $("input[name='id[]']").each(function () {
          if ($(this).prop("checked") == true) {
            chk++;
          }
        });
        if (chknum == chk) {
          //全选
          $("#checkall").prop("checked", true);
        } else {
          //不全选
          $("#checkall").prop("checked", false);
        }
      }



      //批量删除
      function DelSelect() {
        var Checkbox = false;
        var chk_id_arr = [];
        $("input[name='id[]']").each(function () {
          if (this.checked == true) {
            Checkbox = true;
            chk_id_arr.push($(this).val());

          }
        });

        if (Checkbox) {

          layer.confirm('您确认要删除选中的记录吗?', {
            btn: ['确定', '取消'] //按钮
          }, function () {

            //执行删除操作
            $.ajax({
              type: 'post',
              url: "{:U('Goods/del')}",
              data: { id: chk_id_arr },
              dataType: 'json',
              success: function (res) {

                layer.msg(res.msg, { icon: res.code });

                res.code == '1' ? setTimeout("goURL('" + res.url + "')", 500) : '';
              }

            });

          });

        }
        else {

          layer.alert('请选择您要删除的记录!', {
            skin: 'layui-layer-molv', //样式类名
            closeBtn: 0
          });
          return false;
        }
      }


    </script>



  </body>

</html>